package com.btl.component.st.handler;

import cn.dev33.satoken.exception.NotLoginException;
import com.btl.boot.core.dto.response.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class SaTokenExceptionHandler {

    /**
     * token异常
     *
     * @return <Void>
     */
    @ExceptionHandler(NotLoginException.class)
    @ResponseStatus(HttpStatus.UNAUTHORIZED)
    public R<Void> handleSaTokenException(Exception e) {
        log.error("登录异常 ex={}", e.getMessage());
        return R.fail("会话不存在或已失效");
    }

}
